package fr.cephb.locustree;

import java.io.Serializable;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import fr.cephb.json.JSONBuilder;
import fr.cephb.json.JSONable;

public class TrackChrom
	implements Serializable,JSONable
	{
	private static final long serialVersionUID = 1L;
	private Integer chrom_id;
	private Integer track_id;
	
	public static class Binding
		extends TupleBinding<TrackChrom>
		{
		@Override
		public TrackChrom entryToObject(TupleInput in)
			{
			return new TrackChrom(in.readInt(),in.readInt());
			}
		@Override
		public void objectToEntry(TrackChrom o, TupleOutput out)
			{
			out.writeInt(o.getTrackId());
			out.writeInt(o.getChromosomeId());
			}
		}
	public TrackChrom(Track t,ChromInfo ci)
		{
		this(t.getId(),ci.getId());
		}
	public TrackChrom(Integer track_id,Integer chrom_id)
		{
		this.track_id=track_id;
		this.chrom_id=chrom_id;
		}
	public Integer getTrackId()
		{
		return track_id;
		}
	public Integer getChromosomeId()
		{
		return chrom_id;
		}
	
	@Override
	public String toJSON()
		{
		return new JSONBuilder().
			put("track-id", getTrackId()).
			put("chrom-id", getChromosomeId()).
			getString();
		}
	
	@Override
	public int hashCode()
		{
		final int prime = 31;
		int result = 1;
		result = prime * result + chrom_id.hashCode();
		result = prime * result + track_id.hashCode();
		return result;
		}
	
	@Override
	public boolean equals(Object obj)
		{
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		TrackChrom other = (TrackChrom) obj;
		if (!chrom_id.equals(other.chrom_id)) return false;
		if (!track_id.equals(other.track_id)) return false;
		return true;
		}
	
	@Override
	public String toString()
		{
		return toJSON();
		}
	}
